package main

import "fmt"

func appendSlice(slice, data []byte) []byte {
	oldLen:=len(slice)
	newLen:=oldLen + len(data);

	if newLen > cap(slice) {
		newSlice:=make([]byte, newLen)
		for i:=0; i<oldLen; i++ {
			newSlice[i]=slice[i]
		}
		slice=newSlice
	} else {
		slice=slice[:newLen]
	}

	for i:=0; i<len(data); i++ {
		slice[oldLen + i] = data[i]
	}

	return slice
}

func main() {
	s:=[]byte{1,2,3}
	s=appendSlice(s, []byte{4,5,6})
	fmt.Println(s)
}
